package pri.lt.parser;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import pri.lt.App;

import java.util.Date;

import static org.junit.Assert.assertTrue;

@SpringBootTest(classes = App.class)
public class SinaParserText {

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testContentUrl1() {
        String url = "https://news.sina.com.cn/c/2019-02-18/doc-ihqfskcp6099808.shtml";
        Parser.ParserResult parserResult = SinaParser.getInstance().parse(url);
        assertTrue("parseUrl " + url, parserResult != null && parserResult.isValid());
    }

    @Test
    public void testContentUrl2() {
        String url = "http://zj.sina.com.cn/news/2019-02-18/detail-ihqfskcp6138257.shtml";
        Parser.ParserResult parserResult = SinaParser.getInstance().parse(url);
        assertTrue("parseUrl " + url, parserResult != null && parserResult.isValid());
    }

    @Test
    public void testContentUrl3() {
        String url = "http://sports.sina.com.cn/basketball/nba/2019-02-18/doc-ihqfskcp6133389.shtml";
        Parser.ParserResult parserResult = SinaParser.getInstance().parse(url);
        assertTrue("parseUrl " + url, parserResult != null && parserResult.isValid());
    }



    @Test
    public void testCommentUrl1() {
        String url = "testCommentUrl";
        Parser.ParserResult parserResult = new Parser.ParserResult();
        parserResult.publishTime = new Date();
        parserResult.commentUrl = "http://comment5.news.sina.com.cn/comment/skin/default.html?channel=gn&newsid=comos-hqfskcp6099808";
        Parser.HotCommentResult hotCommentResult = SinaParser.getInstance().getHotCommentResult(url, parserResult);
        assertTrue("get comment " + parserResult.commentUrl,
                hotCommentResult != null && hotCommentResult.comments != null && hotCommentResult.comments.size() > 0);
    }

}
